package at.fhj.itm11.forum.service.stubs;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import at.fhj.itm11.forum.data.IconDAO;
import at.fhj.itm11.forum.model.Icon;

public class IconDAOStub implements IconDAO {

	private Set<Icon> repo = new HashSet<Icon>();

	@Override
	public List<Icon> retrieveAllIconsOrderedByFileName() {
		List<Icon> result = new ArrayList<Icon>(repo);
		Collections.sort(result, new Comparator<Icon>() {

			@Override
			public int compare(Icon o1, Icon o2) {
				return o1.getFileName().compareTo(o2.getFileName());
			}
		});

		return result;
	}

	@Override
	public Icon findIconById(Long id) {
		for (Icon icon : repo) {
			if (icon.getId().equals(id)) {
				return icon;
			}
		}

		return null;
	}

	public Set<Icon> getRepo() {
		return repo;
	}

	public void setRepo(Set<Icon> repo) {
		this.repo = repo;
	}

}
